package com.petshop.controller;

import com.petshop.dto.LoginDTO;
import com.petshop.dto.PasswordClass;
import com.petshop.pojo.Users;
import com.petshop.service.UsersService;
import com.petshop.utils.Result;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UsersController {
    @Autowired
    private UsersService usersService;

    @PostMapping("/login")
    public Result login(@RequestBody Users users) {
        Result result = usersService.login(users);
        return result;
    }

    /*
    发送手机验证码
     */
    @GetMapping("code")
    public Result sendCode(@RequestParam("phone") String phone, HttpSession session) {
        Result result = usersService.sendCode(phone, session);
        return result;
    }

    /*
    手机号登录
     */
    @PostMapping("/login1")
    public Result login1(@RequestBody LoginDTO loginDTO, HttpSession session) {
        Result result = usersService.login1(loginDTO, session);
        return result;
    }

    @GetMapping("/getUserInfo")
    public Users getUserInfo(@RequestHeader("Authorization") String token) {
        Users users = usersService.getUserInfo(token);
        return users;
    }

    @PostMapping("/checkUsername")
    public Result checkUsername(String username) {
        Result result = usersService.checkUsername(username);
        return result;
    }

    @PostMapping("/regist")
    public Result regist(@RequestBody Users user) {
        Result result = usersService.regist(user);
        return result;
    }

    /*
    修改用户的信息
     */
    @PostMapping("/updateUserInfo")
    public Result updateUserInfo(@RequestBody Users user) {
        Result result = usersService.updateUserInfo(user);
        return result;
    }

    /*
    充值
     */
    @GetMapping("recharge")
    public Result recharge(@RequestParam BigDecimal amount, @RequestHeader("Authorization") String token) {
        Result result = usersService.recharge(amount, token);
        return result;
    }

    /*
    改密码
     */
    @PostMapping("updatePassword")
    public Result updatePassword(@RequestBody PasswordClass passwordClass, @RequestHeader("Authorization") String token) {
        Result result = usersService.updatePassword(passwordClass, token);
        return result;
    }

    /*
    签到
     */
   @PostMapping("/sign")
    public Result sign(  ) {
       Result result = usersService.sign();
       return result;
   }

   /*
   统计截止当前天数的连续签到天数
    */
   @GetMapping("/sign/count")
   public Result signCount() {
       Result result = usersService.signCount();
       return result;
   }
}
